package com.zhongxi.guoyuan.adapter.rewardCoin;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.zhongxi.guoyuan.entity.projectItem.ProjectItemData;
import com.zhongxi.guoyuan.view.rewardCoin.categoryPage.NewRewardItemPage;

import java.util.List;

/**
 * Created by Administrator on 2017/9/27.
 */

public class RewardMyAdapter extends PagerAdapter {
    private List<ProjectItemData> projectItemDatas;
    private Context context;

    public RewardMyAdapter(Context context, List<ProjectItemData> projectItemDatas) {
        this.context=context;
        this.projectItemDatas=projectItemDatas;
    }

    @Override
    public int getCount() {
        if (projectItemDatas!=null){
            return projectItemDatas.size();
        }
        return 0;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return projectItemDatas.get(position).getName();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        NewRewardItemPage itemPage=new NewRewardItemPage(context,projectItemDatas.get(position).getId());
        View view = itemPage.initView();
        itemPage.initData();
        itemPage.initEvent();
        container.addView(view);
        return view;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
       container.removeView((View) object);
    }
}
